
local player = g_playerMgr
local hero = require 'types.hero'

local force1Count = 6
local force2Count = 3
--2个电脑
player.com = {
	player(11),
	player(12),
	['天渊城'] = player(11),
	['人族'] = player(12),
}

--2组玩家
player.force = {
	[1] = {
		[0] = player.com[1],
		player(1),
		player(2),
		player(3),
		player(4),
		player(5),
		player(6),
	},
	[2] = {
		[0] = player.com[2],
		player(8),
		player(9),
		player(10),
	}
}

player.force1Count = force1Count
player.force2Count = force2Count

--玩家结盟
for x = 0, force1Count do
	for y = 0, force2Count do
		player.force[1][x]:setAllianceSimple(player.force[1][y], true)
		player.force[1][x]:setAllianceSimple(player.force[2][y], false)
		if player.force[2][x] and player.force[2][y] then
			player.force[2][x]:setAllianceSimple(player.force[1][y], false)
			player.force[2][x]:setAllianceSimple(player.force[2][y], true)
		end
	end
	player.force[1][x]:setTeam(1)
	player.force[1][x]:enableControl(player(16))
	if player.force[2][x] then
		player.force[2][x]:setTeam(2)
		player.force[2][x]:enableControl(player(16)) --允许控制中立被动的单位
	end
end

--电脑与野怪互相友好
player.force[1][0]:setAllianceSimple(player(13), true)
player.force[2][0]:setAllianceSimple(player(13), true)
player(13):setAllianceSimple(player.force[1][0], true)
player(13):setAllianceSimple(player.force[2][0], true)

g_playerMgr.self:clearMsg()

--设置名字
player.com[1]:setName '天渊城'
player.com[2]:setName '人族'

--玩家离开通报
ac.game:event '玩家-离开' (function(trg, p)
	local hero = p.hero
	local hero_name
	if hero then
		hero_name = hero:get_name()
	else
		hero_name = '没有英雄'
	end
	g_playerMgr.self:sendMsg(('%s%s(%s)|r |cffff1111哭着逃跑了!|r'):format(p:getColorWord(), p:getBaseName(), hero_name))
end)

--玩家离开删除英雄并分钱
ac.game:event '玩家-离开' (function(trg, tp)
	local h = tp.hero
	if h then
		h:add_restriction '隐藏'
		h:add_restriction '缴械'
		h:add_restriction '无敌'
		h:set_high(10000)
		g_heroMgr:getAllHeros()[h] = nil
	end
end)